using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace KeyAuthService.Dialogs
{
    /// <summary>
    /// 消息类型
    /// </summary>
    public enum MessageType
    {
        Info,
        Success,
        Warning,
        Error
    }

    /// <summary>
    /// 现代风格消息对话框
    /// </summary>
    public class ModernMessageBox : Window
    {
        public static void Show(string message, string title = "提示", MessageType type = MessageType.Info)
        {
            var dialog = new ModernMessageBox(message, title, type);
            dialog.ShowDialog();
        }
        
        private ModernMessageBox(string message, string title, MessageType type)
        {
            Title = title;
            Style = (Style)FindResource("DialogWindowStyle");
            MinWidth = 400;
            MinHeight = 180;
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            Topmost = true;
            SizeToContent = SizeToContent.WidthAndHeight;
            ResizeMode = ResizeMode.NoResize;
            ShowInTaskbar = false;
            
            // 创建主容器
            var grid = new Grid();
            grid.Style = (Style)FindResource("DialogContainerStyle");
            
            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            
            // 内容容器
            var contentPanel = new StackPanel
            {
                Margin = new Thickness(0, 0, 0, 20)
            };
            
            // 图标和标题
            var headerPanel = new StackPanel
            {
                Orientation = Orientation.Horizontal,
                Margin = new Thickness(0, 0, 0, 15)
            };
            
            var icon = new TextBlock
            {
                FontSize = 24,
                Margin = new Thickness(0, 0, 10, 0),
                VerticalAlignment = VerticalAlignment.Center
            };
            
            var headerText = new TextBlock
            {
                FontSize = 16,
                FontWeight = FontWeights.SemiBold,
                VerticalAlignment = VerticalAlignment.Center
            };
            
            // 设置图标和标题
            switch (type)
            {
                case MessageType.Success:
                    icon.Text = "✅";
                    headerText.Text = "操作成功";
                    headerText.Foreground = new SolidColorBrush(Color.FromRgb(76, 195, 138));
                    break;
                case MessageType.Warning:
                    icon.Text = "⚠️";
                    headerText.Text = "警告";
                    headerText.Foreground = new SolidColorBrush(Color.FromRgb(255, 159, 67));
                    break;
                case MessageType.Error:
                    icon.Text = "❌";
                    headerText.Text = "错误";
                    headerText.Foreground = new SolidColorBrush(Color.FromRgb(230, 57, 70));
                    break;
                case MessageType.Info:
                default:
                    icon.Text = "ℹ️";
                    headerText.Text = "信息";
                    headerText.Foreground = new SolidColorBrush(Color.FromRgb(67, 97, 238));
                    break;
            }
            
            headerPanel.Children.Add(icon);
            headerPanel.Children.Add(headerText);
            
            contentPanel.Children.Add(headerPanel);
            
            // 消息文本
            var messageText = new TextBlock
            {
                Text = message,
                TextWrapping = TextWrapping.Wrap,
                Style = (Style)FindResource("DialogPromptStyle")
            };
            
            contentPanel.Children.Add(messageText);
            
            // 按钮面板
            var buttonPanel = new StackPanel
            {
                Style = (Style)FindResource("DialogButtonPanelStyle")
            };
            
            // 确定按钮
            var btnOK = new Button
            {
                Content = "确定",
                Style = (Style)FindResource("DialogPrimaryButtonStyle"),
                IsDefault = true,
                IsCancel = true
            };
            
            btnOK.Click += (s, e) => Close();
            
            // 添加按钮到面板
            buttonPanel.Children.Add(btnOK);
            
            // 添加控件到布局
            grid.Children.Add(contentPanel);
            Grid.SetRow(contentPanel, 0);
            
            grid.Children.Add(buttonPanel);
            Grid.SetRow(buttonPanel, 1);
            
            Content = grid;
        }
    }
} 